pub struct TTCCalculation{
    pub headway_offset:f64,
    pub max_velocity:f64,
    pub min_velocity:f64,
}
impl Default for TTCCalculation {
    fn default() -> Self {
        TTCCalculation { 
            headway_offset: 3.7,
             max_velocity: 100.0,
              min_velocity: 0.01 
            }
    }
}

impl TTCCalculation {
    pub fn new() -> Self {
        TTCCalculation {
            ..Default::default()
        }
    }

    pub fn newHeadwayOffset(headway_offset:f64) -> Self {
        TTCCalculation {
            headway_offset:headway_offset,
            ..Default::default()
        }
    }

    fn saturation(&self,mut mio_velocity:f64)->f64{
        mio_velocity=mio_velocity.abs();
        if mio_velocity>self.max_velocity{
            mio_velocity=self.max_velocity;
        }
        else if mio_velocity<self.min_velocity  {
            mio_velocity=self.min_velocity;
        }
        mio_velocity
    }

    pub fn calculation(
        &self,
        mio_distance:f64,
        mio_velocity:f64
    )->(bool,f64){
        let headway=mio_distance-self.headway_offset;
        let mut ttc=headway/self.saturation(mio_velocity);
        if mio_velocity<0.0{
            ttc=ttc*-1.0;
        } 



        (headway<0.1,ttc)

    }

}